package com.szd.qiongyou20.community.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.szd.qiongyou20.R;
import com.szd.qiongyou20.community.bean.RecommendBean;
import com.szd.qiongyou20.utils.BitmapCircleTransformation;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by SZD on 2016/12/29.
 */

public class Recon_RecycylerViewV_Adapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    private Context mContext;
    private List<RecommendBean.DataBean.IndexListBean> mList;

    public Recon_RecycylerViewV_Adapter(Context context, List<RecommendBean.DataBean.IndexListBean> list) {
        mContext = context;
        mList = list;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_community_recommend, null);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        if (holder instanceof ViewHolder) {
            String avatar = mList.get(position).getAvatar();
            String author = mList.get(position).getAuthor();
            String title = mList.get(position).getTitle();
            List<String> bigpic_arr = mList.get(position).getBigpic_arr();
            String forum = mList.get(position).getForum();
            String reply_time = mList.get(position).getReply_time();
            int reply_num = mList.get(position).getReply_num();

            Glide.with(mContext).load(avatar)
                    .transform(new BitmapCircleTransformation(mContext))
                    .into(((ViewHolder) holder).mImageViewRecommendHead);

            ((ViewHolder) holder).mTextViewRecommendName.setText(author);
            ((ViewHolder) holder).mTextViewRecommendTitle.setText(title);
            ((ViewHolder) holder).mTextViewType.setText(forum);
            ((ViewHolder) holder).mTextViewRecommendTime.setText(reply_time);
            ((ViewHolder) holder).mTextViewReplayCount.setText(reply_num+"");


            GridView_Adapter adapter = new GridView_Adapter(mContext, bigpic_arr);
            ((ViewHolder) holder).mGridViewRecommend.setAdapter(adapter);
        }
    }

    @Override
    public int getItemCount() {
        return mList.size();
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        @Bind(R.id.imageView_recommend_head)
        ImageView mImageViewRecommendHead;
        @Bind(R.id.textView_recommend_name)
        TextView mTextViewRecommendName;
        @Bind(R.id.imageView_logo)
        ImageView mImageViewLogo;
        @Bind(R.id.textView_recommend_title)
        TextView mTextViewRecommendTitle;
        @Bind(R.id.gridView_recommend)
        GridView mGridViewRecommend;
        @Bind(R.id.textView_recommend_time)
        TextView mTextViewRecommendTime;
        @Bind(R.id.textView_type)
        TextView mTextViewType;
        @Bind(R.id.textView_replay_count)
        TextView mTextViewReplayCount;

        public ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
